import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:robot3/robot/addQA.dart';
import 'package:robot3/robot/huxingxuanzhe01.dart';
import 'package:robot3/xiangqing3.dart';

import 'customerFragment.dart';
import 'customerRenderDetails.dart';
import 'fanganku.dart';
import 'http.dart';
import 'widgets.dart';

const platformMethodChannel1 = MethodChannel(
  'com.example.flutter_android_activity',
);


final RouteObserver<ModalRoute<void>> routeObserver =
RouteObserver<ModalRoute<void>>();



void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      navigatorObservers: <NavigatorObserver>[routeObserver],
      title: 'Flutter Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      // home: const MyHomePage(title: 'Flutter Demo Home Page'),
      ///可加可不加
      initialRoute: '/',
        routes: <String, WidgetBuilder>{
          '/': (context) =>  HuxingxuanzheScreen(),
          // '/': (context) =>  MyHomePage(title: '1'),
          '/xiangqing': (context) =>  Xiangqing3(),
          '/qa2': (context) =>  HuxingxuanzheScreen(),


          ///以下customerRenderDetails huxingxuanze 正在使用，不能删除或修改
          '/customerRenderDetails': (context) =>  CustomerRenderDetails(),
          '/huxingxuanze': (context) =>  HuxingxuanzheScreen(),

          ///
          ///
          ///

          '/customerFragment': (context) =>  Name1(),
          '/http': (context) => const HttpHomePage(title: '123'),
          // '/xiangqing': (context) => const XiangqingScreen(title: '123'),
          '/fanganku': (context) => const FangankuScreen(title: '123'),
        },
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int _counter = 0;


  // SECTION 2: START COPYING HERE
  void _launchAndroidActivity() {
    platformMethodChannel.invokeMethod(
      'launchActivity',
      {'message': 'Hello from Flutter'},
    );
  }

  void _incrementCounter() {
    setState(() {
      _counter++;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body:Row(
        children: [
          SizedBox(height: 200),
          SizedBox(width: 50),
          RobotOutLineText(),
          SizedBox(width: 10),
          MyButton01(
            text: '打开安卓界面',
            containerColor: Colors.black,
            textColor: Colors.white,
            size: Size(200, 50),
            fontSize: 16.0,
            fontWeight: FontWeight.bold,
            onClick: (text) {
              _launchAndroidActivity();
            },
          ),
          SizedBox(width: 10),
        MyButton01(
            text: 'goto网络请求页',
            containerColor: Colors.black,
            textColor: Colors.white,
            size: Size(200, 50),
            fontSize: 16.0,
            fontWeight: FontWeight.bold,
            onClick: (text) {
              Navigator.of(context).pushNamed('/http');
            },
          ),
          SizedBox(width: 10),
          RobotButton(onClick: (text){
            Navigator.of(context).pushNamed('/http');
          },)
        ],

      )



      // body:Container(
      //             width: 500,
      //             height: 500,
      //   child:       RobotFillMaxSizeCard(content: RobotText(text: "258")),
      //           ),



      // body: RobotCard(
      //   child: TextButton(
      //     onPressed: () {
      //       showRobotPopup(
      //         context,
      //         child: Container(
      //           width: 400,
      //           height: 400,
      //           color: Colors.red[100],
      //         ),
      //         x: 500,
      //         y: 200,
      //       );
      //     },
      //     child: Text('RobotCard'),
      //   ),
      // ),



      // RobotList(height:600)
      //   MyRow(),
      //   Row(
      //     mainAxisAlignment: MainAxisAlignment.spaceEvenly,
      //     children: [
      //       // MyRow(),
      //       CardExample(),
      //       RobotButton(),
      //       RobotText(text: "私库"),
      //       MyCircularProgressIndicator(),
      //       const Padding(
      //         padding: const EdgeInsets.all(0.0),
      //         child: const Text('Hello, World!1'),
      //       ),
      //     ],
      // )
    );
  }
}

class MyCircularProgressIndicator extends StatelessWidget {
  const MyCircularProgressIndicator({super.key});

  @override
  Widget build(BuildContext context) {
    return Center(
      child: CircularProgressIndicator(
        strokeWidth: 4.0, // 线条宽度
        color: Colors.blue, // 主颜色
        backgroundColor: Colors.grey[300], // 背景颜色
      ),
    );
  }
}

// 定义一个函数来显示全屏对话框
void showFullScreenDialog(BuildContext context) {
  showDialog(
    context: context,
    barrierDismissible: false, // 不允许点击外部关闭对话框
    builder: (BuildContext context) {
      return Dialog(
        insetPadding: EdgeInsets.zero, // 让对话框填满屏幕
        backgroundColor: Colors.black.withOpacity(0.3), // 设置背景颜色为黑色30%透明度
        child: Column(
          children: <Widget>[
            Expanded(
              child: Container(
                color: Colors.red.withOpacity(0.0),
                child: Center(
                  child: Text(
                    'This is a Full-Screen Dialog',
                    style: TextStyle(color: Colors.black, fontSize: 24),
                  ),
                ),
              ),
            ),
            // 添加按钮来关闭对话框
            Container(
              padding: EdgeInsets.all(16),
              child: ElevatedButton(
                onPressed: () {
                  Navigator.of(context).pop();
                },
                child: Text('Close'),
              ),
            ),
          ],
        ),
      );
    },
  );
}

// 定义一个单独的函数来显示对话框
void showCustomDialog(BuildContext context) {
  showDialog(
    context: context,
    builder: (BuildContext context) {
      return AlertDialog(
        title: Text('This is an Alert Dialog'),
        content: Text('Do you want to proceed with this action?'),
        actions: <Widget>[
          TextButton(
            onPressed: () {
              // 取消操作
              Navigator.of(context).pop();
            },
            child: Text('Cancel'),
          ),
          TextButton(
            onPressed: () {
              // 确认操作
              Navigator.of(context).pop();
            },
            child: Text('OK'),
          ),
        ],
      );
    },
  );
}

class MyRow extends StatelessWidget {
  MyRow({super.key});

  // // 定义一个自定义的 ButtonStyle
  final ButtonStyle flatButtonStyle = TextButton.styleFrom(
    minimumSize: Size(88, 36), // 最小尺寸
    padding: EdgeInsets.symmetric(horizontal: 16), // 内边距
    shape: const RoundedRectangleBorder(
      borderRadius: BorderRadius.all(Radius.circular(2)), // 圆角半径
    ),
  );

  @override
  Widget build(BuildContext context) {
    return Container(
        // decoration: const BoxDecoration(
        //   borderRadius: BorderRadius.only(
        //       topRight: Radius.circular(10.0),
        //       bottomRight: Radius.circular(10.0)),
        //   color: Colors.white,
        // ),
        // decoration: BoxDecoration(
        //   border: Border.all(
        //     color: Colors.blue,    // 边框颜色
        //     width: 2.0,            // 边框宽度
        //   ),
        // ),
        color: Color(0xFFFFDF00), // 设置背景颜色为金色（gold）
        child: Row(children: [
          RobotList(height: 500),
          SizedBox(width: 10), // 这里设置间隔为 5px
          ElevatedButton(
            child: Text("Tap on this1"),
            style: ElevatedButton.styleFrom(
              backgroundColor: Colors.red,
              elevation: 0,
              shape: RoundedRectangleBorder(
                borderRadius: BorderRadius.circular(8), // 圆角边框
              ),
            ),
            onPressed: () {
              showFullScreenDialog(context);
              // showCustomDialog(context);
            },
          ),

          TextButton(
            style: flatButtonStyle,
            onPressed: () {},
            child: Text('Looks like a FlatButton'),
          ),
          ElevatedButton(
            onPressed: () {
              print('Click!');
            },
            child: const Text('A button1'),
          ),

          // 第一个子组件
          Container(
            width: 100,
            height: 100,
            decoration: BoxDecoration(
              color: const Color(0xff885566),
              border: Border.all(
                width: 1,
              ),
              borderRadius: BorderRadius.circular(16),
            ),
            // color: Color(0x60FFff00),  // 红色并设置50%的透明度
            child:
                Center(child: Text('A', style: TextStyle(color: Colors.white))),
          ),
          SizedBox(width: 10), // 这里设置间隔为 5px
          // 第二个子组件
          CircularProgressIndicator(
            strokeWidth: 4.0, // 线条宽度
            color: Colors.blue, // 主颜色
            backgroundColor: Colors.grey[300], // 背景颜色
          ),
        ]));
  }
}
